<%@ page language="java" pageEncoding="UTF-8"%><%request.setAttribute("ctx", request.getContextPath()); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/pub/frontHead.jsp" %>
</head>
<body>    
<%@ include file="slice/topMenu.jsp"%>
    <div class="center">
<%@ include file="slice/login.jsp"%>
<%@ include file="slice/age.jsp"%>
<jsp:include page="slice/goodsList.jsp" flush="true"><jsp:param name="classId" value="A000"/></jsp:include>
<jsp:include page="slice/goodsList.jsp" flush="true"><jsp:param name="classId" value="B000"/></jsp:include>
<jsp:include page="slice/goodsList.jsp" flush="true"><jsp:param name="classId" value="C000"/></jsp:include>
<jsp:include page="slice/goodsList.jsp" flush="true"><jsp:param name="classId" value="D000"/></jsp:include>
<%@ include file="slice/banner.jsp"%>
	</div>
<%@ include file="slice/footer.jsp"%>
<%@ include file="slice/myFavorite.jsp"%>

<script type="text/javascript" src="${ctx}/front/js/ybxJs.js"></script>
<script type="text/javascript">
<!--
var pageSize=8;//商品列表页面大小

//初始化后自动执行
$(document).ready(function(e) {
	resizeAgeBar(); 
	//自动登录
	checkToken();
	setLoginView(true);
 	//获取列表数据
	doQuery('A000');
	doQuery('B000');
	doQuery('C000');
	doQuery('D000');


});

//查询商品列表
function doQuery(classId){	
	var page=getPage(classId);
	var url="${ctx}/front!getList.action";
	$.post(url, "q_classId="+classId+"&page="+page+"&pageSize="+pageSize+"&q_ageId="+ageId ,function callback(txt){   
			var json = $.parseJSON(txt);
			if (json.code==0) {	
				setRecordCount(json.count,classId);
				createNotes(json.info,classId);				
			}else{
				alert('查询商品列表失败！');
			}
		}	
	);
}
//创建商品列表数据
function createNotes(objs,classId){		
	var c="";
	for(var i=0;i<objs.length;i++){
		var obj=objs[i];		
		c+='<div class="bb_pd_cell">';
		c+='<p class="bb_pd_pic">';
		c+='    <a href="#">';
		c+='        <img src="'+obj.goodsPic+'" />';
		c+='    </a>';
		c+='</p>';
		c+='<p class="bb_pd_desc">';
		c+='    <a href="#">'+obj.goodsName+'</a>';
		c+='</p>';
		c+='<p class="bb_pd_opt">';
		c+='    <a class="bb_pd_meg" title="查看评论" href="javascript:goDetailCmt(\''+obj.goodsId+'\');"><b></b>&nbsp;'+obj.countComment+'</a>';
		c+='    <a class="bb_pd_like" title="喜欢" href="javascript:addLike(\''+obj.goodsId+'\');"><b></b>&nbsp;<span id="likeCount_'+obj.goodsId+'">'+obj.countLike+'</span></a>';        
		c+='</p>';
		c+='<a class="bb_pd_explain" href="javascript:goDetail(\''+obj.goodsId+'\');">';
		c+='    <h3>推荐理由</h3>';
		c+='    <p>'+obj.recommend+'</p>';
		c+='</a>';
		c+='</div>';
	}	
	$('#goods_'+classId).html(c);
}
//移至上一页
function _movePre(classId){	
	var page=parseInt($("#page_"+classId).val());
	if(page==1)return;
	$("#page_"+classId).val(--page);	
	_clickGo(classId);    
}
//移至下一页
function _moveNext(classId){
	var page=parseInt($("#page_"+classId).val());	
	var allPage=parseInt($("#allPage_"+classId).val());	
	if(page==allPage)return;
	$("#page_"+classId).val(++page);	
	_clickGo(classId);
}
//点击go
function _clickGo(classId){	
	if(''==$("#page_"+classId).val())return;
	var page=parseInt($("#page_"+classId).val());
	var allPage=parseInt($("#allPage_"+classId).val());		
	if(page>allPage){
		page=allPage;		
	}else if(page<1){
		page=1;	
	}
	$("#page_"+classId).val(page);	

 	$("#preBt_"+classId).attr("class", page>1?"page_pre":"page_pre_unable");
	$("#nextBt_"+classId).attr("class", page<allPage?"page_next":"page_next_unable");
 	$("#preBt_top_"+classId).attr("class", page>1?"page_pre":"page_pre_unable");
 	$("#nextBt_top_"+classId).attr("class", page<allPage?"page_next":"page_next_unable");
	doQuery(classId);
}
//设置总记录数
function setRecordCount(count,classId){
	var n=Math.floor(count/pageSize)+(count%pageSize==0?0:1);
	$("#allPage_"+classId).val(n);
	$("#allPage_show_"+classId).html("页 共"+n+"页");
}
//获取当前页数
function getPage(classId){
	return parseInt($("#page_"+classId).val());
}
//进入明细
function goDetail(goodsId){
	location.href="${ctx}/front!goDetail.action?goodsId="+goodsId;
}
//进入明细#评论
function goDetailCmt(goodsId){
	location.href="${ctx}/front!goDetail.action?goodsId="+goodsId+"#cmtArea";
}
//添加喜欢
function addLike(goodsId){	
	$.post("${ctx}/favorite!addLike.action", "goodsId="+goodsId ,function callback(txt){   
			var json = $.parseJSON(txt);
			if (json.code==0) {	
				$('#likeCount_'+goodsId).html(parseInt($('#likeCount_'+goodsId).html())+1);
			}else if (json.code==2) {	
				alert('已在喜欢列表中！');
			}else if (json.code==3) {	
				alert('请先登录！');
			}else{
				alert('添加喜欢失败！');
			}
		}	
	);
}
//中间栏位文字
function lanShow(){
	var url="${ctx}/frontSys!getCurrentUser.action";
	$.post(url, "" ,function callback(txt){   
			var json = $.parseJSON(txt);
			if (json.code==0) {	
				var s='';
				if(json.info==null){
					s="我们推荐给您0-1岁宝宝的商品，您可以<a href=\"javascript:viewLogin();\" class=\"enter_detail\">登录</a>后填写宝宝信息来获取更准确的商品";
				}else if(json.info.babyName==''){
					s="我们推荐给您0-1岁宝宝的商品，您可以填写<a href=\"javascript:openWin('${ctx}/frontSys!viewBabyInfo.action',610,560,'宝宝资料');\" class=\"enter_detail\">宝宝信息</a>获取更准确的商品";
				}else{
					s="给您可爱的宝宝<a href=\"javascript:openWin('${ctx}/frontSys!viewBabyInfo.action',610,560,'宝宝资料');\" class=\"enter_detail\">"+json.info.babyName+"</a>挑几样喜欢的东西吧！";
				}			
				$('#lanSpan_A000').html(s);
				$('#lanSpan_B000').html(s);
				$('#lanSpan_C000').html(s);
				$('#lanSpan_D000').html(s);
			}
		}	
	);
}

//-->
</script>
</body>
</html>